import axios from "axios";
import { ElNotification } from "element-plus";
import 'element-plus/es/components/notification/style/css'
import { uesUseinfoStore } from '../stores/useinfo'
import { def } from "@vue/shared";
var UseinfoStore = uesUseinfoStore()
// 1.实例化axios
var server = axios.create({
    timeout: 10 * 1000,
    baseURL: ''
})
// 设置请求拦截
server.interceptors.request.use(
    (config) => {
        config.headers['token'] = UseinfoStore.useinfo.token;
        return config
    },
    (error) => {
        return Promise.reject(error)
    }
)
// 设置相应拦截
server.interceptors.response.use(
    (res) => {
        return res
    },
    (error) => {
        if (error.response.status == 401) {
            ElNotification.error({ message: '登陆过期，请重新登录' })
        } else if (error.response.status == 404) {
            ElNotification.error({ message: '访问路径有误' })
        } else if (error.response.status == 500) {
            ElNotification.error({ message: '服务器内容错误' })
        } else if (error.response.status == 503) {
            ElNotification.error({ message: '服务器不可用' })
        }
        return Promise.reject(error)
    }
)
export default server